package com.datastructure.test.firstnotrepeatingchar;

import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

public class FirstNotRepeatingChar {

    public static void main(String[] args) {
        FirstNotRepeatingChar firstNotRepeatingChar = new FirstNotRepeatingChar();
        System.out.println(firstNotRepeatingChar.FirstNotRepeatingChar("googlel"));
    }

    public int FirstNotRepeatingChar(String str) {
        char[] c = str.toCharArray();
        int[] b = new int[128];
        for (int i = 0; i < c.length; i++) {
            int d = c[i] % 128;
            b[d] = b[d] + 1;
        }
        for (int i = 0; i < c.length; i++) {
            int d = c[i] % 128;
            if (b[d] == 1) {
                return i;
            }
        }
        return -1;
    }
}
